<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        body {}
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <div class="aui-title" id="title">
            系统选择
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div class="aui-grid">
            <div class="aui-row" id="menuGrid" style="margin-bottom: 40px;">
                <!-- <div class='aui-col-xs-3' onclick='goPage("uwmInventoryTask");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>仓库盘点</div></div><div class='aui-col-xs-3' onclick='goPage("uwmInOfStock");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>入库</div></div><div class='aui-col-xs-3' onclick='goPage("uwmInOfStockZc");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>总成入库</div></div><div class='aui-col-xs-3' onclick='goPage("uwmOutOfStock");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>出库</div></div><div class='aui-col-xs-3' onclick='goPage("uwmOutOfStockZc");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>总成出库</div></div><div class='aui-col-xs-3' onclick='goPage("uwmInTransfer");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>库内转移</div></div><div class='aui-col-xs-3' onclick='goPage("uwmInterBankTransfer");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>库间转移</div></div><div class='aui-col-xs-3' onclick='goPage("uwmSHVerification");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>收货验证</div></div><div class='aui-col-xs-3' onclick='goPage("uwmYqgyReceipt");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>收货入库</div></div><div class='aui-col-xs-3' onclick='goPage("uwmTmPrint");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>条码打印</div></div><div class='aui-col-xs-3' onclick='goPage("paBcpComplete");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>半成品完工</div></div><div class='aui-col-xs-3' onclick='goPage("mpProduction");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>生产上料</div></div><div class='aui-col-xs-3' onclick='goPage("uwmStock");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>仓库现存量</div></div><div class='aui-col-xs-3' onclick='goPage("emToolUsedRegister");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>刀具使用登记</div></div><div class='aui-col-xs-3' onclick='goPage("emProcessingTimes");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>加工次数登记</div></div><div class='aui-col-xs-3' onclick='goPage("emEquipBindTool");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>设备已登记刀具</div></div><div class='aui-col-xs-3' onclick='goPage("emToolScrap");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>刀具报废</div></div><div class='aui-col-xs-3' onclick='goPage("sequenceChk");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>顺引校验</div></div><div class='aui-col-xs-3' onclick='goPage("emModule");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>设备管理</div></div><div class='aui-col-xs-3' onclick='goPage("tjclFactoryReceive");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>天津到厂收货</div></div><div class='aui-col-xs-3' onclick='goPage("uwmInOfStockTjcl");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>天津入库业务</div></div><div class='aui-col-xs-3' onclick='goPage("uwmOutOfStockTjcl");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>天津出库业务</div></div><div class='aui-col-xs-3' onclick='goPage("uwmInterBankTransferTjcl");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>天津库间转移</div></div><div class='aui-col-xs-3' onclick='goPage("uwmYqgyReceiptTjcl");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>天津看板收货</div></div><div class='aui-col-xs-3' onclick='goPage("uwmInOfStockZcTjcl");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>天津总成入库</div></div><div class='aui-col-xs-3' onclick='goPage("qcmChkBillCreate");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>检测单创建</div></div><div class='aui-col-xs-3' onclick='goPage("qcmChkBill");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>检测单处理</div></div><div class='aui-col-xs-3' onclick='goPage("qcProductRepair");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>总成问题录入</div></div><div class='aui-col-xs-3' onclick='goPage("JPush");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>极光测试</div></div><div class='aui-col-xs-3' onclick='goPage("uwmScanRuleChk");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>三点照合校验</div></div><div class='aui-col-xs-3' onclick='goPage("usmExceptionBill");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>异常发起</div></div><div class='aui-col-xs-3' onclick='goPage("usmExceptionTask");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>我的任务</div></div><div class='aui-col-xs-3' onclick='goPage("usmExceptionBillHistory");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>异常历史查询</div></div><div class='aui-col-xs-3' onclick='goPage("mbfOpDoc");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>工序文件查看</div></div><div class='aui-col-xs-3' onclick='goPage("qcPointChangeBill");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>变化点发起</div></div><div class='aui-col-xs-3' onclick='goPage("qcPointChangeTaskA");'><i class='aui-iconfont aui-icon-uwm'></i><div class='aui-grid-label'>变化点任务A</div></div> -->
            </div>
        </div>
    </div>

    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item aui-active" tapmode>
            <i class="aui-iconfont aui-icon-home"></i>
            <div class="aui-bar-tab-label">首页</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toPhoto()">
            <i class="aui-iconfont aui-icon-camera"></i>
            <div class="aui-bar-tab-label">拍照</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toScanner()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toMsgList()">
            <i class="aui-iconfont aui-icon-mail"></i>
            <div class="aui-bar-tab-label">消息</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="setPerson()">
            <i class="aui-iconfont aui-icon-my"></i>
            <div class="aui-bar-tab-label">个人中心</div>
        </div>
    </footer>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //极光
    var jpush = null;

    //初始化
    apiready = function() {

        api.addEventListener({
            name: 'loginSuccess'
        }, function(ret, err) {

            if (ret) {

                $api.html($api.byId("menuGrid"), "");
                window.location.reload();

            } else {}
        });

        jpush = api.require('ajpush');

        //id
        jpush.getRegistrationId(function(ret) {
            var registrationId = ret.id;
            // console.log("registrationId:" + registrationId);

            //根据用户绑定id
            saveRegistrationId(registrationId);

        });

        api.addEventListener({
            name: 'appintent'
        }, function(ret, err) {
            // alert('通知被点击，收到数据：\n' + JSON.stringify(ret)); //监听通知被点击后收到的数据
            if (ret && ret.appParam.ajpush) {

                var ajpush = ret.appParam.ajpush;
                var id = ajpush.id;
                console.log(id);
                var title = ajpush.title;
                var content = ajpush.content;
                var extra = ajpush.extra;
                console.log(extra);

                alert('通知被点击，收到数据：\n' + content);
            }
        });

        api.addEventListener({
            name: 'pause'
        }, function(ret, err) {
            onPause(); //监听应用进入后台，通知jpush暂停事件
        })

        api.addEventListener({
            name: 'resume'
        }, function(ret, err) {
            onResume(); //监听应用恢复到前台，通知jpush恢复事件
        })

        //极光推送初始化
        initJPush();

        //绑定别名
        // bindAliasAndTags();

        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            if (ret) {
                //alert( JSON.stringify( ret ) );
                api.confirm({
                    title: '退出提示',
                    msg: '确定要退出程序吗?',
                    buttons: ['确定', '取消']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 1) {
                        api.closeWidget({
                            silent: true
                        });
                    }
                });
            } else {
                alert(JSON.stringify(err));
            }
        });

        //获取菜单
        searchMenu();

    }

    //根据用户绑定ID
    function saveRegistrationId(registrationId) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveRegistrationId";
        var data = {
            values: {
                registrationId: registrationId,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    // console.log("registrationId绑定成功");

                    //失败
                } else if (myobj.code == "1") {
                    // console.log("registrationId绑定失败");
                    api.toast({
                        msg: myobj.message,
                        duration: 6000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //极光推送初始化
    function initJPush() {
        jpush.init(function(ret, err) {
            if (ret && ret.status) {
                // console.log('极光推送初始化：操作成功!');
            } else {
                // console.log('极光推送初始化：操作失败!');
            }
        });
    }

    //极光绑定别名
    function bindAliasAndTags() {
        var un = localStorage.getItem('un');
        var param = {
            alias: un,
            tags: []
        };
        jpush.bindAliasAndTags(param, function(ret, err) {
            console.log('极光绑定别名处理结果：\n' + JSON.stringify(ret));
        });
    }

    //极光推送-app恢复
    function onResume() {
        jpush.onResume();
        console.log('JPush onResume');
    }

    //极光推送-app暂停
    function onPause() {
        jpush.onPause();
        console.log('JPush onPause');
    }

    //获取菜单
    function searchMenu() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchMenu";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var html = "";
                    var list = eval(myobj.list);
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<div class='aui-col-xs-3' onclick='goPage(\"" + list[i].url + "\");'>";
                        html += "<i class='aui-iconfont aui-icon-uwm'></i>";
                        html += "<div class='aui-grid-label'>" + list[i].title + "</div>";
                        html += "</div>";
                    }
                    // console.log("htmlhtmlhtml",html);
                    $api.html($api.byId("menuGrid"), html);

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 6000
                    });
                }
            }
        });
    }

    //跳转页面
    function goPage(url) {
        var arr = url.split("?");
        var name = arr[0];
        var query = {};
        if (arr.length > 1) {
            //参数
            var paramStr = arr[1];
            var paramArr = paramStr.split("&");
            for (var i = 0; i < paramArr.length; i++) {
                var params = paramArr[i].split("=");
                query[params[0]] = params[1];
            }

        }
        //打开页面
        api.openWin({
            name: name,
            url: name + '.html',
            pageParam: {
                query: query,
            }
        });
    }

    //拍照
    function toPhoto() {
        api.getPicture({
            sourceType: 'camera', //library    图片库//camera    相机         // albm  相册
            encodingType: 'jpg', //返回图片类型，jpg或png
            mediaValue: 'pic', //媒体类型，图片或视频
            destinationType: 'url', //返回数据类型，指定返回图片地址或图片经过base64编码后的字符串
            allowEdit: true, //是否可以选择图片后进行编辑，支持iOS及部分安卓手机
            //quality: 80,
            targetWidth: 400, //压缩后的图片宽度，图片会按比例适配此宽度
            targetHeight: 500, //压缩后的图片高度，图片会按比例适配此高度
            saveToPhotoAlbum: true //拍照或录制视频后是否保存到相册
        }, function(ret, err) {
            if (ret) {
                //alert( JSON.stringify( ret ) );
            } else {
                //alert( JSON.stringify( err ) );
            }
        });
    }

    //扫描
    function toScanner() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function(ret, err) {
            // getEquipByCode(ret);
        });
    }

    //消息
    function toMsgList() {
        api.openWin({
            name: "msglist",
            url: "msglist.html"
        });
    }

    //个人中心
    function setPerson() {
        api.openWin({
            name: "person",
            url: "person.html"
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
